<template>

    

  <div class="app-container">
   <div class="head">
      <div class="headinput">
        <i>患者姓名:</i>
        <el-input
          placeholder="请输入患者姓名"
          v-model="tempname.name"
          size="small"
          clearable>
        </el-input>

        <el-button
          type="primary"
          style="margin-left: 3px"
          plain
          icon="el-icon-search"
          size="small"
          class="select1"
          @click="dzmpQuery">查询</el-button>

        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="small"
          class="add"
          @click="handleAdd"
          >新增</el-button>
       
      
      </div>
    </div>
       
     


    <el-table  :data="list">
      <el-table-column label="ID" align="center" prop="patientId" />
      <el-table-column label="所属医院" align="center" prop="hospitalId" />
      <el-table-column label="患者姓名" align="center" prop="name" />
      <el-table-column label="微信" align="center" prop="openid" />
      <el-table-column label="患者电话" align="center" prop="mobile" />
      <el-table-column label="患者性别" align="center" prop="sex" />
      <el-table-column label="地址信息" align="center" prop="address" />
      <el-table-column label="过敏信息" align="center" prop="allergyInfo" />
       
    <!-- <el-table-column>
      <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          
          @click="handleUpdate(row)"
        
        >修改</el-button></el-table-column> -->

        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
           
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="100"
      layout="total, sizes, prev, pager, next, jumper"
      :total=total>
    </el-pagination>


    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <!-- <el-form-item label="患者编号" prop="patientId">
          <el-input v-model="form.fileId" placeholder="请输入患者编号" />
        </el-form-item> -->
        <el-form-item label="医院ID" prop="hospitalId">
          <el-input-number v-model="form.hospitalId" placeholder="请输入所属医院" />
        </el-form-item>
       
        <el-form-item label="患者姓名" prop="name">
          <el-input v-model="form.name" placeholder="请输入患者姓名" />
        </el-form-item>
        <el-form-item label="微信" prop="openid">
          <el-input v-model="form.openid" placeholder="请输入患者微信" />
        </el-form-item>
        <el-form-item label="患者电话" prop="mobile">
          <el-input v-model="form.mobile" placeholder="请输入患者电话" />
        </el-form-item>
         <el-form-item label="患者性别" prop="sex">
          <el-radio-group v-model="form.sex">
            <el-radio :label="1" aria-checked="checked">男</el-radio>
            <el-radio :label="2">女</el-radio>
          </el-radio-group>
        </el-form-item>
         <el-form-item label="地址信息" prop="address">
          <el-input v-model="form.address"  type="textarea"  placeholder="请输入地址信息" />
        </el-form-item>
         <el-form-item label="过敏信息" prop="allergyInfo">
          <el-input v-model="form.allergyInfo"  type="textarea"  placeholder="请输入过敏信息" />
        </el-form-item>

        
        
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
   
  </div>
</template>

<script>
// import { getList,add,getByid,deleteFile,updateFile } from "@/api/patient/patientfile";
import {querydp,adddp,deldp,getById,updatedp } from "@/api/dzmorder";


export default {
  // doctor  医生  
  name: "doctor",
  data() {
    return{
        // 分页后的当前页数据
        list: [],
        //当前数据页的第几页
        currentPage: 1,
        // 总数据条数xx
        total: 0,
        // 每页显示多少行数据,默认为10条
        pagesize: 10,
        // 代表是从后端获取的所有数据
        ticket: [],
        //对话框是否显示
        open:false,
        form:"",
        title: "",
        single: true, 
        multiple:true,
           // 遮罩层
        loading: true,
       // 导出遮罩层
        exportLoading: false,
        // 表单参数
         form: {},
      // 表单校验
          rules: {},
      // 显示搜索条件
      showSearch: true,
      tempname:{
        name:""
      },

    }   
  },
  created() {
        this.getPatientFile();
  },
  methods: {
     // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        
      };
      // this.resetForm("form");
    },
     /** 修改按钮操作 */
    // handleUpdate(row) {
    //   this.reset();
    //   const id = row.id || this.ids
    //   getCompare(id).then(response => {
    //     this.form = response.data;
    //     this.open = true;
    //     this.title = "修改招标报价对比";
    //   });
    // },
    /** 查询患者表数据 */
    getPatientFile() {
          //this.listLoading = true;
         querydp().then(response => {
            console.log(response.data[0]+"患者数据");
            if(response.code === 200){
                this.ticket = response.data;
                //获取返回数据的总行数
                this.total = response.data.length;
                // 获取当前页的数据,此方法在下方定义
                this.getDoctorInfo()
                this.$message({
                    message: '数据加载成功',
                    type: 'success'
                })
            } else {
                // 失败提示信息
                this.$$message({
                    message: '数据加载错误',
                    type: 'error'
                })
            }
         });
    },
     dzmpQuery() {
      querydp(this.tempname).then((response) => {
        console.log(this.tempname)
        if (response.code === 200) {
          this.ticket = response.data;
          //获取返回数据的总行数
          this.total = response.data.length;
          // 获取当前页的数据,此方法在下方定义
          this.getDoctorInfo();
          this.$message({
            message: "数据加载成功",
            type: "success",
          });
        } else {
          // 失败提示信息
          this.$$message({
            message: "数据加载错误",
            type: "error",
          });
        }
      });
    },

    // 此方法用来获取当前页的数据
    getDoctorInfo(){
        // 清空表格的list 数据
        this.list=[];
        // 获取当前页的数据
        for(
            let i = (this.currentPage - 1) * this.pagesize;
            i < this.total;
            i++
        ){
            // 将便利的数据添加到 list 里面
            this.list.push(this.ticket[i]);
            // 判断是否达到每一页的要求
            if(this.list.length === this.pagesize)
            break;
        }
    },
    // 分页时修改每页的行数,这里会自动传入一个size
    handleSizeChange(size) {
        // 修改当前每页的数据行数
        this.pagesize = size;
        // 数据重新分页
        this.getDoctorInfo();
    },
    // 调整当前的页码
      handleCurrentChange(pageNumber) {
          // 修改当前的页码
        this.currentPage = pageNumber;
        //数据重新分页
        this.getDoctorInfo();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加患者信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.patientId || this.patientId
      console.log(">>>>>>"+id)
     
      getById(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改患者信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.patientId != null) {
            updatedp(this.form).then(response => {
              // this.$modal.msgSuccess("修改成功");
              this.$message({
                    message: '数据修改成功',
                    type: 'success'
                })
              this.open = false;
              this.getPatientFile();
            });
          } else {
            // console.log(this.form.hospitalId+this.form.name+this.form.openid+"这是患者数据");
            adddp(this.form).then(response => {
             
              this.getPatientFile();
              this.$message({
                    message: '数据添加成功',
                    type: 'success'
                })
              this.open = false;
              
            });
          }
        }
      });
    },
    // /** 删除按钮操作 */
    // handleDelete(row) {
    //   const ids = row.fileId || this.fileId;
    //   this.$modal.confirm('是否确认删除患者编号为"' + ids + '"的数据项？').then(function() {
    //     return deleteFile(ids);
    //   }).then(() => {
    //     this.getList();
    //     this.$modal.msgSuccess("删除成功");
    //   }).catch(() => {});
    // },
    handleDelete(row){
        const ids = row.patientId || this.patientId;
        deldp(ids).then(response =>{
             
             this.$message({
                    message: '数据删除成功',
                    type: 'success'
                });
             this.getPatientFile();

        })
        
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$modal.confirm('是否确认导出所有患者信息？').then(() => {
        this.exportLoading = true;
        return exportPayment(queryParams);
      }).then(response => {
        this.$download.name(response.msg);
        this.exportLoading = false;
      }).catch(() => {});
    }
  }
  
};
</script>


<style lang="scss" scoped>
.app-container {
  width: 100%;
  height: 100%;
}

.app-container .head {
  margin: 0 auto;
  margin-top: 25px;
  width: 95%;
  height: 50px;
  background-color: white;
  box-shadow: 0 0 5px 1px #eeedf2;
}

.app-container .head .el-input {
  //  line-height: 20px;
  margin-top: 10px;
  //  size: 10;
  width: 15%;
}

.app-container .head i {
  margin-right: 10px;
  margin-left: 10px;
  font-style: normal;
}

.app-container .head .select1 {
  margin-top: 10px;
  margin-left: 20px;
}

.app-container .head .add {
  float: right;
  margin-top: 10px;
  margin-right: 10px;
}

.app-container .el-table {
  margin-top: 20px;
}
</style>>

